Gjs's dbus skeleton implementation does not allow to send a signal to a
specific object only, and while this is an API addition we should do, in
the shell we were repeating the same pattern multiple times.
So let's add an utility function that does that, rather than replicating
the same multiple times.
Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/4270>
(cherry picked from commit
1cde9840ee14338936d06e484f14fb7d00729160)
import {ServiceImplementation} from './dbusService.js';
-import {loadInterfaceXML} from './misc/dbusUtils.js';
+import {emitSignalToDestination, loadInterfaceXML} from './misc/dbusUtils.js';
const NotificationsIface = loadInterfaceXML('org.freedesktop.Notifications');
const NotificationsProxy = Gio.DBusProxy.makeProxyWrapper(NotificationsIface);
_emitSignal(sender, signalName, params) {
if (!sender)
return;
- this._dbusImpl.get_connection()?.emit_signal(
- sender,
- this._dbusImpl.get_object_path(),
- 'org.freedesktop.Notifications',
- signalName,
- params);
+ emitSignalToDestination(this._dbusImpl, sender, signalName, params);
}
_untrackSender(sender) {
xml.substring(ifaceStartIndex, ifaceEndIndex) +
xmlFooter);
}
+
+/**
+ * Emits a D-Bus signal to the given destination bus name.
+ *
+ * @param {Gio.DBusInterfaceSkeleton} dbusImpl - The D-Bus implementation
+ * @param {string|null} destination - The destination bus name or null
+ * @param {string} signalName - The signal name
+ * @param {GLib.Variant|null} params - The signal parameters or null
+ */
+export function emitSignalToDestination(dbusImpl, destination, signalName, params) {
+ const connection = dbusImpl.get_connection();
+ const info = dbusImpl.get_info();
+ connection.emit_signal(
+ destination,
+ dbusImpl.get_object_path(),
+ info?.name ?? null,
+ signalName,
+ params);
+}
import * as ModalDialog from './modalDialog.js';
import * as Main from './main.js';
+import {emitSignalToDestination} from '../misc/dbusUtils.js';
import {loadInterfaceXML} from '../misc/fileUtils.js';
const AudioDevice = {
}
_onDeviceSelected(dialog, device) {
- const connection = this._dbusImpl.get_connection();
- const info = this._dbusImpl.get_info();
const deviceName = Object.keys(AudioDevice)
.filter(dev => AudioDevice[dev] === device)[0].toLowerCase();
- connection.emit_signal(
- this._audioSelectionDialog._sender,
- this._dbusImpl.get_object_path(),
- info ? info.name : null,
- 'DeviceSelected',
+
+ emitSignalToDestination(this._dbusImpl,
+ this._audioSelectionDialog._sender, 'DeviceSelected',
GLib.Variant.new('(s)', [deviceName]));
}
import * as Main from './main.js';
import * as Screenshot from './screenshot.js';
+import {emitSignalToDestination} from '../misc/dbusUtils.js';
import {loadInterfaceXML} from '../misc/fileUtils.js';
import {DBusSenderChecker} from '../misc/util.js';
import {ControlsState} from './overviewControls.js';
if (!destination)
return;
- const connection = this._dbusImpl.get_connection();
- const info = this._dbusImpl.get_info();
-
const context = global.create_app_launch_context(0, -1);
const token = context.get_startup_notify_id(null, []);
if (deviceNode)
params['device-node'] = GLib.Variant.new('s', deviceNode);
- connection.emit_signal(
+ emitSignalToDestination(
+ this._dbusImpl,
destination,
- this._dbusImpl.get_object_path(),
- info?.name ?? null,
signal,
GLib.Variant.new('(ua{sv})', [action, params]));
}